{include file="public/header" /}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.css"}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.js"}
    {load href="__CSS__video-js.min.css"}
    {load href="__JS__video.min.js"}
<style>
    #des, #des input {
        width: 40px;
        text-align: center;
    }

    #id {
        width: 78px;
    }

    .bs-checkbox {
        width: 36px;
        height: 40px
    }

    .fixed-table-toolbar .columns, .fixed-table-toolbar .search {
        margin-left: 0px;
        margin-top: 0px
    }

    #title span {
        float: right;
        margin-left: 3.333px;
    }

    .search {
        margin-bottom: 0px !important;
    }

    .asdlkjasd {
        background: #1ab394;
        color: #fff
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content {:config('adminClass.main')}">
    <div class="ibox float-e-margins">
        {include file="public/tophead"}
        {include file="public/top" /}
        <div class="ibox-content">
            {include file="public/topsection"}
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="fixed-table-toolbar loadClick">
                        <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='0'}asdlkjasd{/eq}{/present}" href="{:url('lists',['status'=>0])}">审核</a>
                        <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='1'}asdlkjasd{/eq}{else /}asdlkjasd{/present}" href="{:url('lists',['status'=>1])}">通过</a>
                        <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='-1'}asdlkjasd{/eq}{/present}" href="{:url('lists',['status'=>-1])}">拒绝</a>
                        <a class="btn btn-default btn-outline {present name='state'}{eq name='state' value='0'}asdlkjasd{/eq}{/present}" href="{:url('lists',['state'=>0])}">待抽取</a>
                    </div>
                    <div class="fixed-table-toolbar loadClick">
                        <form  method="get" action="">
                            <div class="pull-left search">
                                <div class="columns columns-right btn-group pull-left" >
                                    <div class="columns columns-right btn-group pull-left" >
                                        <select class="form-control" name="search_typeid">
                                            <option value="" >内容</option>
                                            <option value="user_id" {eq name="search_typeid" value="user_id" }selected{/eq}>用户id</option>
                                            {php}
                                            if(input('?param.search_typeid')){
                                            $typeidname=input('param.search_typeid');
                                            }else{
                                            $typeidname='';
                                            }
                                            {/php}
                                            {$typeidname}
                                        </select>
                                    </div>
                                </div>
                                {php}
                                if(input('?param.search_typeid') || input('?param.search_name')){
                                {/php}
                                <div class="pull-right search">
                                    <a class="btn btn-w-m btn-link" href="{:url('lists')}">返回管理</a>
                                </div>{php}
                                }
                                {/php}
                                <div class="pull-right search">
                                    <button style="border-radius:0px; border:1px solid #e5e6e7; border-left:0px" class="btn btn-default btn-outline" id="search-btn" type="submit">搜索</button>
                                </div>
                                <div class="pull-right search">
                                    <input class="form-control input-outline" id="filter" type="text"
                                           {php}
                                           if(input('?param.search_name')){
                                    if(input('param.search_name')){
                                    echo "value='".input('search_name')."'";
                                    }
                                    }
                                    {/php}
                                    name="search_name" placeholder="输入标题搜索">
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="example">
                        <form class="form-horizontal" method="post">
                            <table data-toggle="table">
                                <thead>
                                <tr>
                                    <th class="bs-checkbox"><input type="checkbox" id="delidAll"></th>
                                    <th data-align="center">ID</th>
                                    <th data-align="center">用户</th>
                                    <th>内容</th>
                                    <th>图片/视频</th>
                                    <th data-align="center">发布时间</th>
                                    <th data-align="center">审核时间</th>
                                    <th data-align="center">删除时间</th>
                                    <th data-align="center">状态</th>
                                    <th data-align="center">管理</th>

                                </tr>
                                </thead>
                                <tbody id="form">
                                {volist name="data" id="v" key="k"}
                                <tr id="id{$v.id}" class="class">
                                    <td id="delid" ><input name="delAll[]" type="checkbox" value="{$v.id}"></td>
                                    <td id="id">{$v.id}</td>
                                    <td >
                                    {php}
                                    $user = _user($v['user_id']);
                                    {/php}
                                        <a onclick="member('{$v.user_id}')" style="color:#40BCF7">{$user['name']}</a><br/>({$user['id']})({$user['sex']})<br />({$user['age']}岁)
                                    </td>
                                    <td id="title">

                                        <a>
                                            <?php echo $v['content']; ?>
                                        </a>


                                    </td>
                                    <td>
                                        {volist name="$v.images" id="img"}
                                        <a href="{:strpos($img, 'http')===false?'__ROOT__':''}{$img}" target="_blank">
                                            <img style="width:80px;height:80px;" src="{:strpos($img, 'http')===false?'__ROOT__':''}{$img}"/>
                                        </a>
                                        {/volist}
                                    </td>
                                    <td>
                                        <span {php}if(date('Y-m-d')==date('Y-m-d',strtotime($v['create_time'])))echo 'style="color: #ed5565"';{/php}>{$v.create_time}</span>
                                    </td>
                                    <td>
                                        <span {php}if(date('Y-m-d')==date('Y-m-d',strtotime($v['audit_time'])))echo 'style="color: #ed5565"';{/php}>{$v.audit_time}</span>
                                    </td>
                                    <td>
                                        <span {php}if(date('Y-m-d')==date('Y-m-d',strtotime($v['delete_time'])))echo 'style="color: #ed5565"';{/php}>{$v.delete_time}</span>
                                    </td>
                                    <td id="hide{$v.id}">{if condition="$v.status eq '0'"}<span style="color: #ed5565">审 核</span>{elseif condition="$v.status eq '1'" /}<span style="color: #1ab394">通 过</span>{elseif condition="$v.status eq '-1'" /}<span style="color: #ed5565">拒 绝</span> {$v.reason}{/if}</td>
                                    <td>
                                        <div class="btn-group">
                                            <div data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">操作 <span class="caret"></span>
                                            </div>
                                            <ul class="dropdown-menu">
                                                <!-- <li><a onclick="info('{$v.id}')">抽取详情</a></li>
                                                <li class="divider"></li> -->
                                                {switch name="$v.status"}
                                                {case value="-1"}
                                                <li><a onClick="shenhe({$v.id},'0')">审核</a></li>
                                                <li><a onClick="shenhe({$v.id},'1')"><span style="color: #1ab394; ">通过</span></a></li>
                                                {/case}
                                                {case value="0"}
                                                <li><a onClick="shenhe({$v.id},'1')"><span style="color: #1ab394; ">通过</span></a></li>
                                                <li><a onClick="shenhe({$v.id},'-1')"><span style="color: #ed5565; ">拒绝</span></a></li>
                                                {/case}
                                                {case value="1"}
                                                <li><a onClick="shenhe({$v.id},'-1')"><span style="color: #ed5565; ">拒绝</span></a></li>
                                                <li><a onClick="shenhe({$v.id},'0')">审核</a></li>
                                                {/case}
                                                {/switch}
                                                <!-- <li class="divider"></li>
                                                <li><a onclick="del('{$v.id}')">删除</a>
                                                </li> -->
                                            </ul>
                                        </div>
                                    </td>

                                </tr>
                                {/volist}
                                </tbody>

                            </table>
                        </form>
                    </div>
                </div>
            </div>
            <hr>
            <div class="row row-lg">
                <div class="col-sm-6 loadClick">
                    <a  class="btn btn-outline btn-default" onclick="alla(1)">
                        批量通过
                    </a>
                    <a  class="btn btn-outline btn-default" onclick="alla(-1)">
                        批量拒绝
                    </a>
                    <a  class="btn btn-outline btn-default" onclick="alla(0)">
                        批量审核
                    </a>
                    <a class="btn btn-outline btn-default" onclick="alla('del')">
                        批量删除
                    </a>
                </div>
                <div class="col-sm-6 pages">{$page}</div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
    $(document).ready(function(){
        $('#desAll').click(function(){
            var des=$(".form-horizontal").serialize();
            ajaxFun("post",'{:url('article/desAll')}',des,'json',function(ret){
                if(ret){
                    if(ret.ret){
                        self.location.reload();
                    }else{
                        layer.msg(ret.err)
                    }
                }else{
                    swal_msg("错误",ret,"error");
                }
            })
        })

        $('#delidAll').click(function(){
            $('input[type=checkbox]').each(function(){
                var self=$(this);
                if(!self.prop('checked')){
                    self.prop('checked',true);
                }else{
                    self.prop('checked',false);
                }
            });
        })
    });
    function del(id){
        swal_del(id,"{:url('del')}")
    }
    function alla(types){
        var all=$(".form-horizontal").serialize();
        var alls=$(".form-horizontal").serializeArray();
        console.log(JSON.stringify(alls))

        ajaxFun("post",'{:url('shenheAll')}?type='+types,all,'json',function(ret){

            if(ret){
                var text
                switch(types)
                {
                    case -1:
                        text = '<span class="btn btn-primary btn-xs" style="background-color: #414141;border-color:#414141">拒 绝</span>';
                        break;
                    case 0:
                        text = '<span class="btn btn-default btn-xs">审 核</span>';
                        break;
                    case 1:
                        text = '<span class="btn btn-primary btn-xs">通 过</span>';
                        break;
                    case 2:
                        text = '<span class="btn btn-primary btn-xs">通 过</span>';
                        break;
                }
                for(var i=0;i<alls.length;i++){
                    if(types=='del'){
                        $('#id'+alls[i]['value']).remove();
                    }else{
                        $('#hide'+alls[i]['value']).html(text);
                    }
                }
                layer.closeAll('loading'); 
                swal_msg('操作成功')
            }
        })

    }
    function info(id) {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['50%', '80%'],
                type: 2,
                content: '{:url("info")}?id='+id
            });
        });
    }
    function into(id) {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("into")}?id='+id
            });
        });
    }
    var reasons = JSON.parse('{$rejects}');
    var reasonHtml = '';
    reasons.forEach(item=>{
        reasonHtml += `<div style="margin:5px 10px;cursor: pointer;" onclick="inputEnter('${item.reason}')">${item.reason}</div>`
    })
    function inputEnter(v) {
        $('#extraInput').val(v)
    }
  function shenhe(id,value){
    if(value == -1){
        var extraContent = `<div>
                                <textarea class="layui-layer-input" id="extraInput"></textarea>
                                <div style="display:flex;flex-wrap:wrap;padding-top:20px;">${reasonHtml}</div>
                            </div>`;

      layer.prompt({
        formType: 2,
        value: '',
        title: '请输入拒绝原因',
        content: extraContent, // 额外的内容
        area: ['500px', '400px'] //自定义文本域宽高
      }, function(reason, index, elem){
        shenheAction(id, value, reason)
        layer.close(index);
      });
    } else {
      shenheAction(id,value)
    }
  }
  function shenheAction(id,value,reason='') {
      ajaxFun("post","{:url('authadd')}",{id:id,shenhe:value,reason},'json',function(ret){
          if(ret){
              if(ret.ret){
                  layer.msg(ret.ret)
                  window.location.reload()
              }else{
                  layer.msg(ret.err)
              }
          }else{
              swal_msg("错误",ret,"error");
          }
      })
  }

    function member(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("member/index")}?search=id&name='+id
            });
        });
    }

</script>
 